package com.zfk.transaction.controller;

import com.zfk.transaction.entity.Dynamic;
import com.zfk.transaction.service.DynamicService;
import com.zfk.transaction.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动态控制器
 */

@RestController
@RequestMapping("/dynamic")
@Api("DynamicController")
public class DynamicController {

    @Autowired
    private DynamicService service;

    @GetMapping("/isHot")
    @ApiOperation("获得host动态数据")
    public Response getDynamic(@RequestParam String is_hot){
        System.out.println("isHot = "+is_hot);
        List<Dynamic> result = service.getByIsHot(is_hot);
        return Response.ok(result);
    }


    @PostMapping("/addDynamic")
    @ApiOperation("新增动态")
    public Response addDynamic(@RequestParam Dynamic dynamic){
        int result = service.addDynamic(dynamic);

        return Response.ok();
    }

    @PostMapping("/updateDynamic")
    @ApiOperation("修改动态")
    public Response updateDynamic(@RequestParam Dynamic dynamic){
        int result = service.updateDynamic(dynamic);
        return Response.ok();
    }

    @GetMapping("/deleteDynamic")
    @ApiOperation("删除动态数据")
    public Response deleteData(@RequestParam int post_id){
        service.deleteDynamic(post_id);
        return Response.ok();
    }

}
